// const host = 'http://127.0.0.1:8888';
const host = 'https://pjsh.xuebaeasy.com';
function request (url, method, data, header = {}) {
  wx.showLoading({
    title: '加载中'
  })
  return new Promise((resolve, reject) => {
        wx.request({
          url:host+url,
          method: method,
          data: data,
          header: {
            'Content-Type': 'application/json',
          },
          success: function (res) {
            wx.hideLoading();
            resolve(res.data)
          },
          fail: function (res) {
            wx.hideLoading()
            // reject(false)
          },
          complete: function () {
            wx.hideLoading()
          }
        })
  })
}

function get (obj) {
  return request(obj.url, 'GET', obj.data)
}

function post (obj) {
  return request(obj.url, 'POST', obj.data)
}

export default {
  request,
  get,
  post,
  host
}
